package com.morgan.storageperlib.saf

import android.content.Intent
import android.net.Uri
import androidx.activity.result.ActivityResult
import androidx.activity.result.contract.ActivityResultContract
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import com.morgan.storageperlib.saf.ReadFileHandler
import com.morgan.storageperlib.utils.Utils

/**
 *description：读取String
 *<br>author：caowugao
 *<br>time：2021/3/8 0008 16:11
 */
class ReadStringHandler(act : AppCompatActivity, contract : ActivityResultContract<Intent, ActivityResult> = ActivityResultContracts.StartActivityForResult(), callback : (Boolean, Uri?, String?) -> Unit) : ReadFileHandler(act, contract, { success, uri, input ->
    if (!success) {
        callback.invoke(false, null, null)
    } else {
        callback.invoke(true, uri, Utils.inputStream2String(input))
    }
}) {
}